package com.gr.catanddog_common.utils;


import com.gr.catanddog_common.exception.BisException;
import lombok.Data;

import java.io.Serializable;

@Data
public class Response<T> implements Serializable {
    /*是否成功，默认为true*/
    private boolean success = true;
//    响应信息
    private String message;
    // token
    private String token;
    //响应数据
    private T data;

    //成功响应
    public static <T> Response<T> success(){
        Response<T> response =  new Response<>();
        return response;
    }
    public static <T> Response<T> success(String token){
        Response<T> response =  new Response<>();
        response.setToken(token);
        return response;
    }
    public static <T> Response<T> success(String token,String message){
        Response<T> response =  new Response<>();
        response.setToken(token);
        response.setMessage(message);
        return response;
    }
    public static <T> Response<T> success(T data, String token){
        Response<T> response = new Response<>();
        response.setData(data);
        response.setToken(token);
        return response;
    }
    public static  <T> Response<T> success(T data){
        Response<T> response = new Response<>();
        response.setData(data);
        return  response;
    }
    //失败响应
    public static <T>Response<T> fail(){
        Response<T> response = new Response<>();
        response.setSuccess(false);
        return  response;
    }

    public static <T>Response<T> fail(String message){
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setMessage(message);
        return  response;
    }

    public static <T> Response<T> fail(String message,String token){
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setToken(token);
        response.setMessage(message);
        return response;
    }

    public static <T> Response<T> fail(BisException bisException,String token){
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setToken(token);
        response.setMessage(bisException.getErrorMsg());
        return response;
    }

}
